<template>
  <!--节点复核 -->
  <a-modal class="nodeReview-dialog" title="节点复核" :visible="visible" width="900px" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
    <a-form-model ref="ruleForm" :model="form" :label-col="{ lg: { span: 6 }, sm: { span: 6 } }" :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }">
      <custom-form :formList="formList" :form="form" :is-emit="false" :editModel="''"> </custom-form>
    </a-form-model>
  </a-modal>
</template>
<script>
import monthPlanApi from '@/api/construction/monthPlanApi'
export default {
  name: 'nodeReview',
  props: {
    // 显示隐藏
    visible: {
      type: Boolean,
      default: false
    },
    // 类型（0 月计划 1周计划）
    type: {
      type: String,
      default: ''
    },
    // 节点ID
    nodeId: {
      type: String,
      default: ''
    }
  },
  watch: {
    visible: {
      handler(val) {
        this.form = {
          status: true,
          reviewSituation: '',
          fileIds: [],
          type: this.type,
          nodeId: this.nodeId,
          reviewEmployeeId: this.userInfo.employee.id,
          reviewEmployeeName: this.userInfo.employee.name,
          reviewDate: this.$dateFormat(new Date(), 'D'),
        }
      },
    }
  },
  data() {
    return {
      form: {},
      confirmLoading: false
    }
  },
  computed: {
    userInfo() {
      return this.$userInfo()
    },
    formList() {
      return [
        {
          keyName: 'status',
          type: 'a-switch',
          formClass: 'switch',
          label: '是否复核通过',
          attrs: {
            checkedChildren: '是',
            unCheckedChildren: '否'
          }
        },
        {
          keyName: 'reviewSituation',
          type: 'BaseTextarea',
          label: '复核情况说明',
          span: 24,
          attrs: {
            maxLength: 3000
          }
        },
        {
          keyName: 'reviewEmployeeName',
          type: 'BaseInput',
          disabled: true,
          label: '复核人',
          span: 12
        },
        {
          keyName: 'reviewDate',
          type: 'BaseInput',
          disabled: true,
          label: '复核时间',
          span: 12
        },
        {
          keyName: 'fileIds',
          type: 'uploadFile',
          label: '附件',
          span: 24,
          businessCode: 'BIM02'
        }
      ]
    }
  },
  methods: {
    handleOk() {
        let that = this;
        let str = this.form.status?'请确认是否要提交复核结果?':'复核不通过后，该节点状态将变更为审核不通过，请确认是否要提交复核结果？';
        this.$confirm({
          title: '温馨提示',
          content: str,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            return that.submit()
          },
          onCancel() {
          },
        })
    },
    handleCancel() {
      this.$emit('update:visible', false)
    },
    submit(){
      this.confirmLoading = true
      const form = this.$clone(this.form)
      form.status = form.status ? '2' : '1'
      form.fileIds = form.fileIds.map(item => item.commonId)
      monthPlanApi.createReview(form)
        .then((res) => {
          if (res.code === 200) {
            this.$emit('submit')
          }
        })
        .finally((err) => {
          this.confirmLoading = false
          this.$emit('update:visible', false)
        })
    }
  },
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.nodeReview-dialog {
  @{deep} .switch .ant-form-item-control-wrapper {
    width: calc(100% - 230px);
  }
}
</style>